//
//  MineWalletBandCardViewController.m
//  copyrightTrading
//
//  Created by 郭子一 on 2020/10/6.
//  Copyright © 2020 郭子一. All rights reserved.
//

#import "MineWalletBandCardViewController.h"
#import "MineWalletBandCardCell.h"
@interface MineWalletBandCardViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;

@end

@implementation MineWalletBandCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)setupUI
{
    self.view.backgroundColor = RGB_VALUE(0xF5F5F5);
    
    UIView *headerView = [UIView new];
    headerView.backgroundColor = RGB_VALUE(0xDC0000);
    [self.view addSubview:headerView];
    [headerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.offset(0);
        make.height.mas_equalTo(Height_NavBar);
    }];
    
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setImage:[UIImage imageNamed:@"whiteBack"] forState:UIControlStateNormal];
    [backBtn addTarget:self action:@selector(backBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setHitEdgeInsets:UIEdgeInsetsMake(-15, -15, -15, -15)];
    [headerView addSubview:backBtn];
    [backBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-14);
        make.left.offset(18);
        make.width.height.mas_equalTo(16);
    }];
    
    UILabel *titleLabel = [UILabel new];
    titleLabel.text = @"绑定银行卡";
    titleLabel.font = JSS_MEDIUM_FONT(17);
    titleLabel.textColor = RGB_VALUE(0xFFFFFF);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    [headerView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-9);
        make.centerX.offset(0);
        make.width.mas_equalTo(135);
        make.height.mas_equalTo(24);
    }];
    
    _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain];
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [_tableView registerClass:[MineWalletBandCardCell class] forCellReuseIdentifier:@"MineWalletBandCardCell"];
    [self.view addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.top.equalTo(headerView.mas_bottom).offset(10);
        make.height.mas_equalTo(132);
    }];
    
    UIButton *loginBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [loginBtn setTitle:@"确定" forState:UIControlStateNormal];
    [loginBtn setTitleColor:RGB_VALUE(0xFFFFFF) forState:UIControlStateNormal];
    [loginBtn.titleLabel setFont:JSS_MEDIUM_FONT_4];
    loginBtn.backgroundColor = RGB_VALUE(0xDC0000);
    loginBtn.layer.masksToBounds = YES;
    loginBtn.layer.cornerRadius = 14;
    [loginBtn addTarget:self action:@selector(loginBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:loginBtn];
    [loginBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.offset(-42);
        make.right.offset(-31);
        make.left.offset(31);
        make.height.mas_equalTo(56);
    }];
}

- (void)backBtnClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)loginBtnClick:(UIButton *)sender
{
    MineWalletBandCardCell *cell = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
    MineWalletBandCardCell *cell1 = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
    MineWalletBandCardCell *cell2 = [self.tableView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
    NSLog(@"%@==%@==%@",cell.inputTextF.text,cell1.inputTextF.text,cell2.inputTextF.text);
    if (NULLString(cell.inputTextF.text) || NULLString(cell1.inputTextF.text) || NULLString(cell2.inputTextF.text)) {
        [self showMessage:@"银行卡信息为空"];
        return;
    }
    NSDictionary *paramDic = @{
        @"bank":cell.inputTextF.text,
        @"account":cell1.inputTextF.text,
        @"account_user":cell2.inputTextF.text
    };
    [[APIManager sharedNetManager] requestWithMethod:HttpRequestTypePost URLString:@"bindbank" parameters:paramDic done:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
    } fail:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
    }];
}

- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section
{
    return 3;
}
#define COLOR_WITH_RGB(R,G,B,A) [UIColor colorWithRed:R green:G blue:B alpha:A]
- (UITableViewCell *)tableView:(UITableView *)tableView
         cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    MineWalletBandCardCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MineWalletBandCardCell"];
    if (indexPath.row == 0) {
        cell.titleLab.text = @"银行卡号";
    } else if (indexPath.row == 1) {
        cell.titleLab.text = @"持卡人";
    } else if (indexPath.row == 2) {
        cell.titleLab.text = @"开户行";
    }
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

    return 44;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

@end
